package com.sicheng.lc.周赛.分类.dp;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/14 20:32
 */
public class 统计全为1的正方形子矩阵 {
    //https://leetcode.cn/problems/count-square-submatrices-with-all-ones/
    public int countSquares(int[][] dp) {
        int m = dp.length;
        int n = dp[0].length;
        int res = 0;
        for (int i = 0; i < m; i++) {

            for (int j = 0; j < n; j++) {
                if (i != 0 && j != 0)
                    dp[i][j] = Math.min(Math.min(dp[i - 1][j - 1], dp[i][j - 1]), dp[i - 1][j]) + 1;
                res += dp[i][j];

            }
        }
        return res;
    }
}
